<?php
include('../../include/functions.inc.php');
include('../../include/conversor.php');
$f = $db->query_select("cllg_factura", "SERIE= " . sqlValue(getParam("SERIE"), "text") . " AND NUMERO=" . sqlValue(getParam("NUMERO"), "int"));
$h = $f[0];
$asign = array();
$fullname = "";
$career = "";
if ($h["FK_STUDENT"] != NULL) {
    $stud = $asign = $db->queryToArray("select a.FIRST_NAME,a.SECOND_NAME,a.LAST_NAME from cllg_student a where a.ID=" . $h["FK_STUDENT"]);
    $fullname = $stud[0]["FIRST_NAME"] . " " . $stud[0]["SECOND_NAME"] . " " . $stud[0]["LAST_NAME"];
    $asign = $db->query_toArray("select a.FK_CAREER,b.NAME from cllg_student_assign a,cllg_career b where a.FK_CAREER=b.ID AND a.FK_STUDENT=" . $h["FK_STUDENT"]);
    $career = $asign[0]["NAME"];
}
$d = $db->query_select("cllg_factura_detalle", "FK_FACTURA=" . sqlValue($h["ID"], "int"));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>factura</title>
        <style type="text/css">
            <!--
            #fecha {
                position:absolute;
                left:510px;
                top:25px;
                width:205px;
                height:25px;
                z-index:1;
            }
            #nofact{
                position:absolute;
                left:495px;
                top:15px;
                width:205px;
                height:25px;
                z-index:1;
            }
            #nombre {
                position:absolute;
                left:55px;
                top:55px;
                width:451px;
                height:22px;
                z-index:2;
            }
            #dir {
                position:absolute;
                left:75px;
                top:78px;
                width:452px;
                height:25px;
                z-index:1;
            }
            #nit {
                position:absolute;
                left:650px;
                top:85px;
                width:100px;
                height:24px;
                z-index:3;
            }
            body {
                font-family: Arial;
                font-size: 14px;
                font-weight: bold;
            }
            #montoletras {
                position:absolute;
                left:50px;
                top:230px;
                width:400px;
                height:22px;
                z-index:7;
                font-family: Arial;
                font-size: 12px;
            }

            -->
        </style>
        <script>
            <?php
            $url = getParam("URL");
            if( isset($url) ) {
                ?>
                var url="<?php echo $url; ?>";
                <?php
            }
            else {
                ?>
                var url = 'data.php?operation=new';
                <?php
            }
            ?>
            window.onload = function() {
                window.print();
                if( url!=null ) {
                    document.form1.action=url;
                }
                document.form1.submit();
            }
        </script>
    </head>
    <body>
        <?= getParam("NUMERO") ?>_<?= getParam("SERIE") ?>
        <div id="fecha"><?php echo date("d"); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo date("M"); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo date("Y"); ?></div>
        <div id="nombre"><?php echo $h["NOMBRE"]; ?></div>
        <div id="dir"><?php echo $h["DIRECCION"]; ?></div>
        <div id="nit"><?php echo $h["NIT"]; ?></div>
        <?php
        $total = 0;
        $line = 210;
        foreach ($d as $i) {
            $total+=$i["SUBTOTAL"];
            ?>
            <div id="" style="font-size: 12px; position:absolute; left:42px; top:<?php echo $line; ?>px; width:319px; height:19px; z-index:4;"><?php echo $i["DESCRIPCION"]; ?></div>
            <div id="" style="font-size: 12px; position:absolute; left:725px; top:<?php echo $line; ?>px; width:100px; height:21px; z-index:5;"><?php echo number_format($i["SUBTOTAL"], 2); ?></div>
            <?php
            $line+=21;
        }
        ?>
        <div id="" style="position:absolute; left:725px; top:230px; width:103px; height:21px; z-index:6;">
            <?php echo number_format($total, 2); ?>
        </div>
        <!--div id="" style="position:absolute; left:50px; top:270px; width:350px; height:22px; z-index:7; font-family: Arial; font-size: 12px;" >EFECTUAMOS PAGOS TRIMESTRALES DEL ISR</div-->
        <div id="" style="position:absolute; left:200px; top:200px; width:350px; height:30px; z-index:7; font-family: Arial; font-size: 14px;" >
            <?php echo $fullname; ?><br />
            <?php echo $career; ?>
        </div>
        <div id="montoletras"><?php echo convertir($total); ?></div>
        <form id="form1" name="form1" method="get" action="data.php">
            <input type="hidden" name="operation" value="new" readonly="readonly" />
        </form>
    </body>
</html>